package ui.swing.button.toggle;

import java.awt.FlowLayout;

import javax.swing.ButtonGroup;
import javax.swing.ImageIcon;
import javax.swing.JCheckBox;
import javax.swing.JFrame;
import javax.swing.JToggleButton;

public class ToggleButtonDemo extends JFrame {

	private static final long serialVersionUID = 1362303358169585461L;

	public ToggleButtonDemo() {
		super("ToggleButton Demo");
		getContentPane().setLayout(new FlowLayout());
		ButtonGroup buttonGroup = new ButtonGroup();
		for (int k = 0; k < 4; k++) {
			char ch = (char) ('1' + k);
			JToggleButton button = new JCheckBox("Button" + ch, k == 0);
			// new JRadioButton();
			// new JCheckBox();
			button.setMnemonic(ch);
			button.setEnabled(k < 3);
			button.setToolTipText("This is button" + ch);
			//button.setIcon(new ImageIcon("/resources/images/green.gif"));
			//button.setSelectedIcon(new ImageIcon("/resources/images/red.gif"));
			//button.setRolloverIcon(new ImageIcon("/resources/images/yellow.gif"));
			//button.setRolloverSelectedIcon(new ImageIcon("/resources/images/yellow.gif"));

			button.setIcon(new ImageIcon(getClass().getResource("/resources/images/green.gif")));
			button.setSelectedIcon(new ImageIcon(getClass().getResource("/resources/images/red.gif")));
			button.setRolloverIcon(new ImageIcon(getClass().getResource("/resources/images/yellow.gif")));
			button.setRolloverSelectedIcon(new ImageIcon(getClass().getResource("/resources/images/yellow.gif")));
			getContentPane().add(button);
			buttonGroup.add(button);
		}
		pack();
	}

	public static void main(String args[]) {
		ToggleButtonDemo frame = new ToggleButtonDemo();
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.setVisible(true);

		System.out.println(ToggleButtonDemo.class.getResource("/resources/images/yellow.gif").getFile());
	}
}
